package mybatis.generator;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.api.ProgressCallback;
import org.mybatis.generator.api.VerboseProgressCallback;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Hello world!
 *
 */
public class Generator 
{
    public static void main(String[] args ) {
        Generator generator = new Generator();
        generator.run("mybatis_admin_tables.xml"); //pow generator
    }
    
    public void run(String configFileName){
    	try{
    		List<String> warnings = new ArrayList<String>();
            try {
            	//hkt config
//         	   File configFile = new File(this.getClass().getClassLoader().getResource("mybatis_admin_tables.xml").getPath());
//         	   File configFile = new File(Generator.class.getClassLoader().getResource("mybatis_ecmall_tables.xml").getPath());
         	   File configFile = new File(Generator.class.getClassLoader().getResource(configFileName).getPath());
                boolean overwrite = true;
                ConfigurationParser cp = new ConfigurationParser(warnings);
                Configuration config = cp.parseConfiguration(configFile);
                DefaultShellCallback callback = new DefaultShellCallback(overwrite);
                MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
                ProgressCallback progressCallback = new VerboseProgressCallback();
                myBatisGenerator.generate(progressCallback);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            for (String warning : warnings) {
                System.out.println(warning);
            }
    	}catch(Exception e){
    		System.out.println(e);
    	}
    }
}
